<template>
  <el-input-number
      v-model="value"
      :disabled="disabled"
      :clearable="!field.not_null"
      controls-position="right"
      style="width: 100%"
      :min="format.min"
      :max="format.max"
      :step="format.step"
      :precision="format.precision"
      :step-strictly="format.tep_strictly"
      :value-on-clear="field.not_null ? 0 : null"
  />
</template>

<script setup lang="ts">
import {computed} from "vue";
import type {MetaField} from "../../../types/cell.types";

/**
 * 通用
 */
const props = defineProps<{
  modelValue: any,
  disabled: boolean,
  field: MetaField
}>();

const emit = defineEmits(['update:modelValue'])

const value = computed({
  get: () => props.modelValue,
  set: (v) => emit('update:modelValue', v)
})

/**
 * 格式化
 */
const format = computed(() => {
  return {
    min: props.field.min || -Infinity,
    max: props.field.max || Infinity,
    step: props.field.step || 1,
    precision: props.field.precision || 0,
    tep_strictly: props.field.tep_strictly || false
  }
})
</script>

<style scoped>

</style>